<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        async function getUserName(userId) {
            // 模拟从服务器获取数据的异步操作
            return new Promise((resolve, reject) => {
                setTimeout(() => {
                    if (userId === 1) {
                        resolve('张三')
                    } else if (userId === 2) {
                        resolve('李四')
                    } else {
                        reject('未找到该用户')
                    }
                }, 1000)
            })
        }
        async function main() {
            try {
                const userName = await getUserName(1)
                console.log(userName)
                return userName
            } catch (error) {
                console.log(error)
            }
        }
        main()
    </script>
</body>

</html>